package com.trg.designmodel.commond;

/**
 * @author trg
 * @title: RemoteController
 * @projectName designmodel
 * @description: TODO   调用者
 * @date 2022/3/2123:11
 */
public class RemoteController {
    //开启的命令集合
    Commond onCommond[];

    //关闭的命令集合
    Commond offCommond[];

    Commond undoCommond;

    //对命令集合进行初始化

    public RemoteController() {
        onCommond = new Commond[5];
        offCommond = new Commond[5];

        for (int i = 0; i < 5; i++) {
            this.onCommond[i] = new NoCommond();
            this.offCommond[i] = new NoCommond();
        }
    }

    public void setCommand(int no, Commond onCommond, Commond offCommond) {
        this.onCommond[no] = onCommond;
        this.offCommond[no] = offCommond;
    }

    public void turnOnButton(int no) {
        onCommond[no].execute();
        undoCommond = onCommond[no];
    }

    public void turnOffButton(int no) {
        offCommond[no].execute();
        undoCommond = offCommond[no];
    }

    public void undoButtonWasPushed(){
        undoCommond.undo();
    }

}
